home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 031a / adg_1_3.zip / DLG-MDLS.C < prev    next >
C/C++ Source or Header  |  1991-02-21  |  4KB  |  128 lines

  1. /****************************************************************************
  2. Module name: Dlg-Mdls.C
  3. Programmer : Jeffrey M. Richter.
  4. *****************************************************************************/
  5.  
  6. #include "..\nowindws.h"
  7. #undef NOCOLOR
  8. #undef NOCTLMGR
  9. #undef NOKERNEL
  10. #undef NOMSG
  11. #undef NOSHOWWINDOW
  12. #undef NOUSER
  13. #undef NOWINMESSAGES
  14. #undef NOWINOFFSETS
  15. #undef NOWINSTYLES
  16. #include <windows.h>
  17.  
  18. #include "dlg-mdls.h"
  19.  
  20. static char _szModalLessResult[] = "ModalLessResult";
  21.  
  22.  
  23. HWND FAR PASCAL CreateModalLessDlgBox (HANDLE hInstance, LPSTR szTemplateName,
  24.       HWND hWndParent, FARPROC DialogFunc, DWORD lInitParam) {
  25.  
  26.    return(CreateDialogParam(hInstance, szTemplateName,
  27.             hWndParent, DialogFunc, lInitParam));
  28. }
  29.  
  30.  
  31. BOOL FAR PASCAL DestroyModalLessDlgBox (HWND hDlg) {
  32.    return(DestroyWindow(hDlg));
  33. }
  34.  
  35.  
  36. int FAR PASCAL ModalLessDlgBox (HWND hDlg, HWND hWndParent, LONG lParam) {
  37.    BOOL fPropFound = FALSE;
  38.    int nResult = NULL, nModalLessShowMsg;
  39.    MSG msg;
  40.  
  41.    EnableWindow(hWndParent, FALSE);
  42.  
  43.    // Register and send the "ModalLessShowMsg" msg to the ModalLess Dlg Box.
  44.    nModalLessShowMsg = RegisterWindowMessage(SZMODALLESSSHOWMSG);
  45.    SendMessage(hDlg, nModalLessShowMsg, 0, lParam);
  46.  
  47.    // Display the modalless dialog box.
  48.    ShowWindow(hDlg, SW_SHOW);
  49.  
  50.  
  51.    // Continue the message loop until the "ModalLessResult" property has been
  52.    // associated with the modalless dialog box.  This happens when the 
  53.    // dialog box function calls the EndModalLessDlgBox function.
  54.  
  55.    while (!fPropFound) {
  56.         GetMessage(&msg, NULL, 0, 0);
  57.       if (!IsDialogMessage(hDlg, &msg)) {
  58.          TranslateMessage(&msg);
  59.          DispatchMessage(&msg);
  60.       }
  61.  
  62.       // Get value of "ModalLessResult" property.  If property does not
  63.       // exist, GetProp returns zero.
  64.       nResult = GetProp(hDlg, _szModalLessResult);
  65.  
  66.       // Try to remove the property.  If RemoveProp returns NULL, the
  67.       // property was never associated with the window and the message 
  68.       // loop must continue.
  69.       fPropFound = RemoveProp(hDlg, _szModalLessResult) != NULL;
  70.    }
  71.  
  72.    EnableWindow(hWndParent, TRUE);
  73.  
  74.    // Hide the modalless dialog box and return the result to the application.
  75.    ShowWindow(hDlg, SW_HIDE);
  76.    return(nResult);
  77. }
  78.  
  79.  
  80. BOOL FAR PASCAL EndModalLessDlgBox (HWND hDlg, int nResult) {
  81.    return(SetProp(hDlg, _szModalLessResult, nResult));
  82. }
  83.  
  84.  
  85. #ifdef _DEMO
  86. //****************************************************************************
  87. // Functions for the ModalLess Dialog Box Demonstration.
  88.  
  89. #include "dialog.h"
  90.  
  91. BOOL FAR PASCAL ModalLessDlgProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
  92.    BOOL fProcessed = TRUE;
  93.  
  94.    if (wMsg == RegisterWindowMessage(SZMODALLESSSHOWMSG)) {
  95.       // Initialize the "EDIT" window with some text whenever the dialog box
  96.       // is about to be shown.
  97.       SetDlgItemText(hDlg, ID_NAME, "Default text");
  98.  
  99.       // Make the "EDIT" window have the focus.
  100.       SetFocus(GetDlgItem(hDlg, ID_NAME));
  101.    }
  102.  
  103.    switch (wMsg) {
  104.       case WM_INITDIALOG:
  105.          break;
  106.  
  107.       case WM_COMMAND:
  108.          switch (wParam) {
  109.             case IDOK:
  110.             case IDCANCEL:
  111.                if (HIWORD(lParam) == BN_CLICKED)
  112.                   EndModalLessDlgBox(hDlg, wParam);
  113.                break;
  114.  
  115.             default:
  116.                break;
  117.          }
  118.          break;
  119.  
  120.       default:
  121.          fProcessed = FALSE;
  122.          break;
  123.    }
  124.    return(fProcessed);
  125. }
  126. #endif
  127.  
  128.